﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class glDRIVE
{
    /*
    函数 gl.simp2
    计算二重积分的Simpson法
    固定一个x，用变步长Simpson法计算一个对y的积分近似值。
    double simp1(double x, double eps, void (*s)(double ,double []), double (*f)(double,double))
    参数 x: 
    参数 eps: 
    返回值 
    */

    public static unsafe string drive_simp2()
    {
        double a, b, eps, s;

        a = 0.0;
        b = 1.0;
        eps = 0.0000001;
        gl.s_x_ya = sim2s;
        gl.f_xy = sim2f;
        s = gl.simp2(a, b, eps);

        return gl.html_table("计算二重积分的Simpson法:", new double[] { s });
    }

    // 计算上下限y1(x)与y0(x)
    private static unsafe void sim2s(double x, double* y)
    {
        y[1] = Math.Sqrt(1.0 - x * x);
        y[0] = -y[1];
        return;
    }

    // 计算被积函数值f(x,y)
    private static double sim2f(double x, double y)
    {
        double z;
        z = Math.Exp(x * x + y * y);
        return (z);
    }
}